Documentation

Demo - 3D Physics - Open Dev Kit Documentation

Open Dev Kit Documentation :: Demo - 3D Physics

Very simple 3D physics-based ball throwing game utilizing OpenGL and Jolt physics. Players can freely move in a 3D environment and shoot balls at objects, watching them react dynamically to physics.

How it Works

  • Game Initialization
      The game's main Scene initializes with a 3D environment containing various physics-enabled objects. The player starts in free-fly mode, allowing movement in all directions. A UI Scene (HUD) is also loaded, displaying control instructions for movement and aiming/shooting.
  • Player Controls
      The Controls Keybinds Resource is responsible for the camera's 3D movement as well as the aiming/shooting. Players can move the camera freely using standard WASD controls, use Space/Shift for ascending/descending, rotate their view by right-clicking and dragging with the mouse, and fire projectiles with the left mouse button.
  • Shooting & Physics Interaction
      When the left mouse button is pressed, a bullet is spawned and launched toward the player's aim direction. Objects hit by the bullet will react thanks to Jolt physics being set in Tools > Project Options.

      The variable gBullet has a Ticked Event which is responsible for despawning bullet actors that leave the Scene (fall below a height of Z=-500). Since the variable is of type "Actor" it also has properties for controlling the bullet actor's model, scale, color etc.

Adding New Objects to the Scene

Follow these steps to add a new shape to the demo:

  1. Create the New Object:
    1. Open Tools > Resources.
    2. Double-click the Sprites Sprite Resource.
    3. Select an empty tile and click the Import Images/Model icon to import your 3D model. You may have to configure its scale and rotation.
    4. Depending on the shape of the model you are importing, click the Add Box Collision/Add Capsule Collision icon ("Shared with whole Tile") to add a new collision box to the sequencer.
    5. Line it up with the model.
  2. Place the New Object:
    1. Load StartScene.
    2. Double click on the Actor object to create it.
    3. On the Properties panel find and click + beside Layers.
    4. On Sprite put the demo's main sprite resource which is Sprites, and set its Tile below to 3. The count of the tiles in a Sprite Resource starts from 0, therefore the 4th tile's # would be 3.
    5. Set its Physics Restitution to a low value like 0.5 (make sure its Physics Type is set to Dynamic).
  3. Test the Game:
      Run the project to verify the new object works as expected.

If you think anything is missing, please feel free to: submit documentation feedback on this page